package com.ytf.test.eighth;

class Grain{
    @Override
    public String toString() {
        return "Grain";
    }
}

class Wheat extends Grain{
    @Override
    public String toString() {
        return "Wheat";
    }
}
class Mill{
    Grain process(){
        return new Grain();
    }
}
class WheatMill extends Mill{
    @Override
    Wheat process() {
        return new Wheat ();
    }
}

/**
 * @author: YTF
 * @date: 2025/1/25 9:57
 * @version: 1.0
 * @description:
 */
public class CovariantReturn {
    public static void main(String[] args) {
        Mill mill = new Mill();
        Grain grain = mill.process();
        System.out.println(grain);

        mill= new WheatMill();
        grain = mill.process();
        System.out.println(grain);

        /**
         * Output:
         * Grain
         * Wheat
         *
         * 注意这里用了 子类覆盖了父类方法 父类接收了子类（进行了向上转型的操作）
         */
    }
}
